﻿using Autofac;
using IterationLife.Datas;
using Util.Domains.Contexts;
using Util.Files;
using Util.Iocs;
using Util.Logs;

namespace IterationLife.Football.MTSports.Configs {
    /// <summary>
    /// 应用程序Ioc配置
    /// </summary>
    public class IocConfig : ConfigBase {
        /// <summary>
        /// 加载配置
        /// </summary>
        protected override void Load( ContainerBuilder builder ) {
            LoadBase( builder );
            LoadDatas( builder );
            LoadRepositories( builder );
            LoadApplicationServices( builder );
            LoadDomainServices( builder );
        }

        /// <summary>
        /// 添加基础设施
        /// </summary>
        private void LoadBase( ContainerBuilder builder ) {
            builder.Register( t => ApplicationContext.User ).As<IUserContext>().InstancePerLifetimeScope();
            builder.Register( t => Log.GetLog() ).As<ILog>().InstancePerLifetimeScope();
            builder.RegisterType<FileManager>().As<IFileManager>().InstancePerLifetimeScope();
            builder.RegisterType<FileUpload>().As<IFileUpload>().InstancePerLifetimeScope();
            builder.RegisterType<UserUploadPath>().As<IUploadPath>().SingleInstance();
        }

        /// <summary>
        /// 添加数据库相关配置
        /// </summary>
        private void LoadDatas( ContainerBuilder builder ) {
            builder.RegisterType<ApplicationUnitOfWork>().As<IApplicationUnitOfWork>().InstancePerLifetimeScope();
        }

        /// <summary>
        /// 加载仓储
        /// </summary>
        private void LoadRepositories( ContainerBuilder builder ) {

        }

        /// <summary>
        /// 加载应用服务
        /// </summary>
        private void LoadApplicationServices( ContainerBuilder builder ) {

        }

        /// <summary>
        /// 加载领域服务
        /// </summary>
        private void LoadDomainServices( ContainerBuilder builder ) {
        }
    }
}
